﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CSUACSelfElevation;
using System.Diagnostics;

namespace Proxy3
{
    public partial class Wifi : Form
    {
        public Wifi()
        {
            InitializeComponent();
        }

        private void Wifi_Load(object sender, EventArgs e)
        {
            button1.FlatStyle = FlatStyle.System;

            NativeMethod.SendMessage(button1.Handle, NativeMethod.BCM_SETSHIELD,
                0, (IntPtr)1);

            button2.FlatStyle = FlatStyle.System;

            NativeMethod.SendMessage(button2.Handle, NativeMethod.BCM_SETSHIELD,
                0, (IntPtr)1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Length < 8)
            {
                MessageBox.Show("密码长度不能小于8");
                return;
            }

            ProcessStartInfo proc = new ProcessStartInfo();
            proc.UseShellExecute = true;
            proc.WorkingDirectory = Environment.CurrentDirectory;
            proc.FileName = "WifiConsole.exe";
            proc.Arguments = "s " + textBox1.Text + " " + textBox2.Text;
            proc.Verb = "runas";
            proc.WindowStyle = ProcessWindowStyle.Hidden;

            try
            {
                Process.Start(proc);
            }
            catch
            {
                // The user refused the elevation.
                // Do nothing and return directly ...
                return;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ProcessStartInfo proc = new ProcessStartInfo();
            proc.UseShellExecute = true;
            proc.WorkingDirectory = Environment.CurrentDirectory;
            proc.FileName = "WifiConsole.exe";
            proc.Arguments = "r";
            proc.Verb = "runas";
            proc.WindowStyle = ProcessWindowStyle.Hidden;

            try
            {
                Process.Start(proc);
            }
            catch
            {
                // The user refused the elevation.
                // Do nothing and return directly ...
                return;
            }
        }
    }
}
